/**
 * Created by 白雨浓 on 2019/6/28 16:56.
 */
import R from "../../../res/R";

export default (self) => {

  const checkName = (rule, value, callback) => {

    if (self.type === R.dialog.EDIT) {
      callback();
    }

    const isSame = self.configs.some(item => item.name === value);

    callback(isSame ? `${value}配置已存在` : undefined);
  };

  return {
    name: [
      {required: true, message: '请输入配置名称', trigger: 'blur'},
      {validator: checkName, trigger: 'blur'},
    ],
    host: [
      {required: true, message: '请输入连接地址', trigger: 'blur'},
    ],
    user: [
      {required: true, message: '请输入用户名', trigger: 'blur'},
    ],
    password: [
      {required: true, message: '请输入密码', trigger: 'blur'},
    ],
    database: [
      {required: true, message: '请输入数据库', trigger: 'change'},
    ],
  }
}
